//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.gui.fixed;

import java.awt.*;
import javax.swing.*;

public class TwoRadioButtom extends JPanel {

    public TwoRadioButtom() {
        leftRadioButton = null;
        jPanel = null;
        rightRadioButton = null;
        initialize();
    }

    private void initialize() {
        setLayout(new BorderLayout());
        setSize(306, 27);
        add(getJPanel(), "Center");
    }

    private JPanel getJPanel() {
        if (jPanel == null) {
            jPanel = new JPanel();
            FlowLayout flowLayout = new FlowLayout();
            jPanel.setLayout(flowLayout);
            flowLayout.setHgap(2);
            flowLayout.setVgap(2);
            jPanel.add(getLeftRadioButton(), null);
            jPanel.add(getRightRadioButton(), null);
            buttonGroup = new ButtonGroup();
            buttonGroup.add(getLeftRadioButton());
            buttonGroup.add(getRightRadioButton());
        }
        return jPanel;
    }

    private JRadioButton getRightRadioButton() {
        if (rightRadioButton == null) {
            rightRadioButton = new JRadioButton();
            rightRadioButton.setText("N/A");
            rightRadioButton.setSelected(true);
            rightRadioButton.setPreferredSize(new Dimension(150, 23));
        }
        return rightRadioButton;
    }

    private JRadioButton getLeftRadioButton() {
        if (leftRadioButton == null) {
            leftRadioButton = new JRadioButton();
            leftRadioButton.setText("N/A");
            leftRadioButton.setPreferredSize(new Dimension(150, 23));
        }
        return leftRadioButton;
    }

    public JRadioButton getLeftRadioB() {
        return getLeftRadioButton();
    }

    public boolean isSelectedLeftRadioB() {
        return getLeftRadioButton().isSelected();
    }

    public void setLeftLabel(String txt) {
        getLeftRadioButton().setText(txt);
    }

    public String getLeftLabel() {
        return getLeftRadioButton().getText();
    }

    public JRadioButton getRightRadioB() {
        return getRightRadioButton();
    }

    public boolean isSelectedRightRadioB() {
        return getRightRadioButton().isSelected();
    }

    public void setRightLabel(String txt) {
        getRightRadioButton().setText(txt);
    }

    public String getRightLabel() {
        return getRightRadioButton().getText();
    }
    private JRadioButton leftRadioButton;
    private JPanel jPanel;
    private JRadioButton rightRadioButton;
    private ButtonGroup buttonGroup;
}
